package exception;

import javax.swing.text.ViewFactory;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Filter;

/**
 * 异常处理机制在IO操作中的应用
 */
public class FinallyDemo2 {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("fos.dat");
            fos.write(1);
        } catch (IOException e) {
            e.printStackTrace();//将错误信息输出到控制台上
        } finally {
            try {
                if (fos!=null){
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
